package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.UserGroupParam;
import com.tarena.lbs.user.pojo.query.UserGroupQuery;
import com.tarena.lbs.user.pojo.vo.UserGroupVO;
import com.tarena.lbs.user.service.UserGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


/**
 * 用户人群业务相关
 */
@Slf4j
@Tag(name = "用户人群管理")
@RestController
public class UserGroupController {
    @Autowired
    private UserGroupService userGroupService;

    @Operation(summary = "人群数据分页列表")
    @PostMapping("/admin/basic/userGroup/list")
    public Result<PageResult<UserGroupVO>> pageList(@RequestBody UserGroupQuery userGroupQuery) throws BusinessException{
        log.debug("查询人群数据参数：{}",userGroupQuery);
        PageResult<UserGroupVO> pageResult =userGroupService.pageList(userGroupQuery);
        log.debug("查询人群数据结果：{}",pageResult);
        return new Result<>(pageResult);
    }

    @Operation(summary = "保存人群数据")
    @PostMapping("/admin/basic/userGroup/save")
    public Result<Void> save(@RequestBody UserGroupParam param)throws BusinessException
    {
        log.debug("保存人群数据参数：{}",param);
        userGroupService.saveUserGroup(param);
        return Result.success();
    }
    @Operation(summary = "删除人群数据")
    @GetMapping("/admin/basic/userGroup/delete")
    public Result<Void> delete(Integer id)throws BusinessException{
        log.debug("删除人群数据参数：{}",id);
        userGroupService.deleteUserGroup(id);
        return Result.success();
    }
}
